package com.iwdnb.gkgz.application.service.router.strategyTradeStatistic;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

import com.iwdnb.gkgz.common.model.dto.StrategyTradeDTO;
import com.iwdnb.gkgz.common.utils.BigDecimalUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

/**
 * 按10日均线涨幅统计
 */
@Service
@Slf4j
public class Avg10RateStrategyTradeStatisticService extends BaseStrategyTradeStatisticService {

    @Override
    public Map<String, List<StrategyTradeDTO>> statisticTradeList(String group, String parentGroup,
        List<StrategyTradeDTO> strategyTradeList) {
        if (CollectionUtils.isEmpty(strategyTradeList)) {
            return null;
        }
        Map<String, List<StrategyTradeDTO>> map = strategyTradeList.stream().collect(
            Collectors.groupingBy(groupFunction));
        return formatStatisticMap(group, parentGroup, map);
    }

    Function<StrategyTradeDTO, String> groupFunction = tradeDTO -> {
        //涨停次日涨幅
        BigDecimal rate = tradeDTO.getV50();
        if (BigDecimalUtils.isLe(rate, BigDecimalUtils.fuNine)) {
            return "-10~-9";
        } else if (BigDecimalUtils.isLe(rate, BigDecimalUtils.fuEight)) {
            return "-9~-8";
        } else if (BigDecimalUtils.isLe(rate, BigDecimalUtils.fuSeven)) {
            return "-8~-7";
        } else if (BigDecimalUtils.isLe(rate, BigDecimalUtils.fuSix)) {
            return "-7~-6";
        } else if (BigDecimalUtils.isLe(rate, BigDecimalUtils.fuFive)) {
            return "-6~-5";
        } else if (BigDecimalUtils.isLe(rate, BigDecimalUtils.fuFour)) {
            return "-5~-4";
        } else if (BigDecimalUtils.isLe(rate, BigDecimalUtils.fuThree)) {
            return "-4~-3";
        } else if (BigDecimalUtils.isLe(rate, BigDecimalUtils.fuTwo)) {
            return "-3~-2";
        } else if (BigDecimalUtils.isLe(rate, BigDecimalUtils.fuOne)) {
            return "-2~-1";
        } else if (BigDecimalUtils.isLe(rate, BigDecimalUtils.zero)) {
            return "-1~0";
        } else if (BigDecimalUtils.isLe(rate, BigDecimalUtils.one)) {
            return "0~1";
        } else if (BigDecimalUtils.isLe(rate, BigDecimalUtils.two)) {
            return "1~2";
        } else if (BigDecimalUtils.isLe(rate, BigDecimalUtils.three)) {
            return "2~3";
        } else if (BigDecimalUtils.isLe(rate, BigDecimalUtils.four)) {
            return "3~4";
        } else if (BigDecimalUtils.isLe(rate, BigDecimalUtils.five)) {
            return "4~5";
        } else if (BigDecimalUtils.isLe(rate, BigDecimalUtils.six)) {
            return "5~6";
        } else if (BigDecimalUtils.isLe(rate, BigDecimalUtils.seven)) {
            return "6~7";
        } else if (BigDecimalUtils.isLe(rate, BigDecimalUtils.eight)) {
            return "7~8";
        } else if (BigDecimalUtils.isLe(rate, BigDecimalUtils.nine)) {
            return "8~9";
        } else if (BigDecimalUtils.isGt(rate, BigDecimalUtils.nine)) {
            return "9~10";
        }
        return "error";
    };


}
